package com.xiaoxu.scala_base.code._1_Scala集合


//import scala.collection.mutable
//import scala.collection.mutable._
object MapApp extends App{


  /**
    * 不可变map
    */
  val a = Map("PK" -> 18, "zhangsan" -> 30)

  val b = Map("PK" -> 18, "zhangsan" -> 30)

  b.getOrElse("PK", 9)




  val c =scala.collection.mutable.Map(""->16)
  //添加
  c("xiaoxu") = 25
  c ++= Map("PK" -> 18, "zhangsan" -> 30)
  c += ("PK" -> 18, "zhangsan" -> 30)

  c.get("xiaoxu")//返回 Option[String]
  c.get("xiaoxu").get
  c.getOrElse("PK", 9)



  for ((key, value) <- b) {
    println(key + " : " + value)
  }


  for (key <- b.keySet) {
    println(key + " : " + b.getOrElse(key, 9))
  }

  for (value <- b.values) {
    println(value)
  }


    for((key,_) <- b) {
      println(key + " : " + b.getOrElse(key, 9) )
    }

}



